package com.pig4cloud.pig.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pig.admin.api.entity.BsVipManageEntity;
import com.pig4cloud.pig.admin.controller.BsVipManageController;
import com.pig4cloud.pig.admin.mapper.BsVipManageMapper;
import com.pig4cloud.pig.admin.service.BsVipManageService;
import com.pig4cloud.pig.common.security.util.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * 会员管理
 *
 * @author pig
 * @date 2025-04-03 17:43:06
 */
@Service
public class BsVipManageServiceImpl extends ServiceImpl<BsVipManageMapper, BsVipManageEntity> implements BsVipManageService {
	private static final Logger log = LoggerFactory.getLogger(BsVipManageController.class);

	/**
	 *
	 * @param bsVipManage
	 * @return
	 */
	@Override
	public boolean saveVip(BsVipManageEntity bsVipManage) {
		bsVipManage.setAccount(bsVipManage.getMobile());
		// 创建人
		bsVipManage.setCreator(SecurityUtils.getUser().getName());
		//创建时间
		bsVipManage.setCreateTime(LocalDateTime.now());
		// 绑定amdin账户为总账户
//		bsVipManage.setAccount(SecurityUtils.getUser().getName());
//		bsVipManage.setAccount(SecurityUtils.getUser().getName());
//		bsVipManage.setAccountId(SecurityUtils.getUser().getId());
		bsVipManage.setAccountId(bsVipManage.getMobile());
		//admin账号赋值激活
		bsVipManage.setLockFlag(0);
		bsVipManage.setDeleteFlag(0);
		bsVipManage.setBalance("0");
		bsVipManage.setMileage("0");
		// 记录新增vip并初始化里程数
		log.info("新增vip:{},{}",bsVipManage.getUserName(),bsVipManage.getBalance());
		baseMapper.insert(bsVipManage);
		return true;
	}
}